<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 1.使用eval 去执行这个字符串

        var exports = {};
        // 模拟exports对象
        // eval   new function
        // 把导出变成字符串
        // 'exports.default = function (a, b) { return a + b }';

        // 使用eval 去执行这个字符串
        eval('var a = 123;exports.default = function (a, b) { return a + b }');

        console.log(exports.default(2, 4));
        console.log('a', a);

        // `var add = require('./add').default; console.log(add(1, 2));`
    </script>

</body>

</html>